<?php
/********************************************************************
 *	Author:
 *		Jestery Liu <jestery@gmail.com>
 *		http://www.pte.cn
 *
 *	File:			PTE.php
 *	Create Date:	2006-12-26 13:01:52 CST
 *******************************************************************/

PTE::setFrameworkPath(dirname(__FILE__));

final class PTE
{
	private function __construct() {}
	
	private static $frameworkPath;
	private static $coreLibsPath;
	private static $applicationsPath;
	private static $projectPath;
	private static $pearPath;
	private static $UserdefinedClassesPath;
	private static $applicationDirFormat = '%s';
	private static $moduleFileFormat = "%s.module.php";
	private static $moduleClassFormat = "%sModule";
	private static $actionMethodFormat = "%sAction";
	private static $modelsPath;
	private static $modelFileFormat = "%s.model.php";
	private static $configFile = null;
	private static $debug = false;
	private static $debugString = 'pte';
	private static $errorHandler = null;

	public static function setProjectPath($path)
	{
		self::$projectPath = self::normalizePath($path);
	}
	
	public static function getProjectPath()
	{
		return self::$projectPath;
	}
	
	public static function setApplicationsPath($path)
	{
		self::$applicationsPath = self::normalizePath($path);
	}
	
	public static function getApplicationsPath()
	{
		return self::$applicationsPath;
	}
	public static function getApplicationPath($appName)
	{
		return self::normalizePath(self::getApplicationsPath().sprintf(self::getApplicationDirFormat(), $appName));
	}
	public static function getApplicationDirFormat()
	{
		return self::$applicationDirFormat;
	}
	public static function setApplicationDirFormat($format)
	{
		self::$applicationDirFormat = $format;
	}
	/**
	 * Set the error handler
	 *
	 * @param string $handler The name of the handler.
	 */
	public static function setErrorHandler($handler = null)
	{
		if ($handler==null)
		{
			$handler = 'ErrorHandler';
			require_once(self::getCoreLibsPath().'ErrorHandler.class.php');
		}
		self::$errorHandler = new $handler();
		set_error_handler(array(self::$errorHandler, 'Handle'), E_WARNING | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE);
	}

	/**
	 * Get the Error_Handler instance;
	 *
	 * @return IError_Handler
	 */
	public static function getErrorHandler()
	{
		return self::$errorHandler;
	}
	
	public static function setFrameworkPath($path)
	{
		self::$frameworkPath = self::normalizePath($path);
		self::$coreLibsPath = self::normalizePath(self::$frameworkPath.'core');
	}
	public static function getFrameworkPath()
	{
		return self::$frameworkPath;
	}
	public static function getCoreLibsPath()
	{
		return self::$coreLibsPath;
	}
	public static function setPearPath($path)
	{
		self::$pearPath = self::normalizePath($path);
	}
	public static function getPearPath()
	{
		return self::$pearPath;
	}
	public static function setUserDefinedClassesPath($path)
	{
		self::$UserdefinedClassesPath = self::normalizePath($path);
	}
	public static function getUserDefinedClassesPath()
	{
		return self::$UserdefinedClassesPath;
	}
	public static function setModuleFileFormat($format)
	{
		self::$moduleFileFormat = $format;
	}
	public static function getModuleFileFormat()
	{
		return self::$moduleFileFormat;
	}
	public static function getModuleFilename($moduleName)
	{
		return sprintf(self::getModuleFileFormat(), $moduleName);
	}
	public static function setModuleClassFormat($format)
	{
		self::$moduleClassFormat = $format;
	}
	public static function getModuleClassFormat()
	{
		return self::$moduleClassFormat;
	}
	public static function getModuleClassName($moduleName)
	{
		return sprintf(self::getModuleClassFormat(), $moduleName);
	}
	public static function setActionMethodFormat($format)
	{
		self::$actionMethodFormat = $format;
	}
	public static function getActionMethodFormat()
	{
		return self::$actionMethodFormat;
	}
	public static function getActionMethodName($actionName)
	{
		return sprintf(self::getActionMethodFormat(), $actionName);
	}
	public static function setModelsPath($path)
	{
		self::$modelsPath = self::normalizePath($path);
	}
	public static function getModelsPath()
	{
		return self::$modelsPath;
	}
	public static function setModelFileFormat($format)
	{
		self::$modelFileFormat = $format;
	}
	public static function getModelFileFormat()
	{
		return self::$modelFileFormat;
	}
	public static function getModelFilename($modelName)
	{
		return sprintf(self::getModelFileFormat(), $modelName);
	}
	public static function setDebug($bool)
	{
		self::$debug = (bool)$bool;
	}
	public static function getDebug()
	{
		return self::$debug;
	}
	public static function setDebugString($string)
	{
		self::$debugString = $string;
	}
	public static function getDebugString()
	{
		return self::$debugString;
	}
	public static function setConfigFile($file)
	{
		self::$configFile = $file;
	}
	public static function getConfigFile()
	{
		return self::$configFile;
	}
	/**
	 * Get Loader class file.
	 *
	 * @return string The full path of the Loader class.
	 */
	public static function getLoaderFile()
	{
		return self::getCoreLibsPath().'Loader.class.php';
	}
	/**
	 * Adds a directory separator to the path.
	 *
	 * @param string $path
	 * @return string The path with ending slash.
	 */
	public static function normalizePath($path)
	{
		return rtrim($path, '/\\').DIRECTORY_SEPARATOR;
	}
}

/* vim: set ts=4 sw=4 ff=unix: */
